<script lang="ts" setup>
import { onMounted, onBeforeUnmount } from 'vue'
import * as echarts from 'echarts';

const pieCharts1 = ref(null)
const pieCharts2 = ref(null)
const lineCharts = ref(null)
let pieOption1 = reactive({})
let pieOption2 = reactive({})
let lineOption = reactive({})
const pieData = [
    { value: 900, name: 'API' },
    { value: 20, name: 'H5' },
    { value: 40, name: '私有化部署' },
    { value: 40, name: 'SDK' },
]

const pieData2 = [
    { value: 1048, name: '智能安防' },
    { value: 735, name: '生态环保' },
    { value: 535, name: '智慧城市' }
]
const initPieEcharts1 = () => {
  pieCharts1.value = echarts.init(document.getElementById("pie-charts1"))
  pieOption1 = {
      tooltip: {
          trigger: 'item',
          show: false
      },
      series: [
          {
              name: 'Access From2',
              type: 'pie',
              radius: '50%',
              label: {
                color: '#000',
                formatter: "{b}：{c}"
              },
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
              data: pieData
          }
      ]
  }
  pieCharts1.value.setOption(pieOption1)
}

const initPieEcharts2 = () => {
  pieCharts2.value = echarts.init(document.getElementById("pie-charts2"))
  pieOption2 = {
      tooltip: {
          trigger: 'item',
          show: false
      },
      series: [
          {
              name: 'Access From2',
              type: 'pie',
              radius: '50%',
              itemStyle: {
                  borderColor: '#fff',
                  borderWidth: 2,
              },
              label: {
                color: '#000',
                formatter: "{b}：{c}"
              },
              labelLine: {
                  show: false,
                  lineStyle: {
                      color: '#fff'  // 设置标示线的颜色
                  }
              },
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
              data: pieData2
          }
      ]
  }
  pieCharts2.value.setOption(pieOption2)
}

const initLineCharts = () => {
  lineCharts.value = echarts.init(document.getElementById("line-charts1"))

  lineOption = {
    // color: ['#80FFA5', '#00DDFF'],

    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    grid: {

      bottom: '13%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        axisTick:{
          show: false //坐标轴刻度线
        },
        axisLine: {  //这是x轴文字颜色
            show: false
        },
        data: ['1.24', '1.25', '1.26', '1.27', '1.28', '1.29', '1.30']
      }
    ],
    yAxis: [
      {
        show: false,
        type: 'value'
      }
    ],
    series: [
      {
        name: 'Line 4',
        type: 'line',
        stack: 'Total',
        smooth: true,
        lineStyle: {
          width: 0
        },
        showSymbol: 'circle',
        
        areaStyle: {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(184, 220, 158)'
            },
            {
              offset: 1,
              color: 'rgb(250, 252, 252)'
            }
          ])
        },
        emphasis: {
          focus: 'series'
        },
        data: [220, 402, 231, 134, 190, 230, 120]
      },
      {
        name: 'Line 5',
        type: 'line',
        stack: 'Total',
        smooth: true,
        lineStyle: {
          width: 0
        },
        showSymbol: 'circle',
        label: {
          show: false,
          position: 'top'
        },
        areaStyle: {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(192, 218, 238)'
            },
            {
              offset: 1,
              color: 'rgb(250, 252, 252)'
            }
          ])
        },
        emphasis: {
          focus: 'series'
        },
        data: [220, 302, 181, 234, 210, 290, 150]
      }
    ]
  };
  lineCharts.value.setOption(lineOption)
}

let active = ref(true)
const chaneActive = () => {
  console.log(11)
  active.value = !active.value
}

onMounted(() => {
  console.log(11)
  initPieEcharts1()
  initPieEcharts2()
  initLineCharts()
  window.onresize = () => {
    pieCharts1.value.clear()
    pieCharts2.value.clear()
    lineCharts.value.clear()
    pieCharts1.value.resize()
    pieCharts2.value.resize()
    lineCharts.value.resize()
    pieCharts1.value.setOption(pieOption1)
    pieCharts2.value.setOption(pieOption2)
    lineCharts.value.setOption(lineOption)
  }
})

onBeforeUnmount(() => {
  pieCharts1.value.clear()
  pieCharts2.value.clear()
  lineCharts.value.clear()
  pieCharts1.value.dispose()
  pieCharts2.value.dispose()
  lineCharts.value.dispose()
})


</script>

<template>
  <div class="home-container">
    <div class="home-content">
      <div class="top-content">
        <div class="left">
          <div class="title">能力统计</div>
          <div class="content">
            <div class="inner-item">
              <div class="digit">
                <div class="big-num">188
                  <div class="type">上架能力</div>
                </div>
                <div class="small-num">22</div>
                <div class="arrow">
                  <div class="rotate"></div>
                </div>
              </div>
            </div>
            <div class="inner-item">
              <div class="digit">
                <div class="big-num">188
                  <div class="type">引入能力</div>
                </div>
                <div class="small-num">22</div>
                <div class="arrow">
                  <div class="rotate"></div>
                </div>
              </div>

            </div>
            <div class="inner-item">
              <div class="digit">
                <div class="big-num">188
                  <div class="type">能力被调用总数</div>
                </div>
                <div class="small-num">22</div>
                <div class="arrow">
                  <div class="rotate"></div>
                </div>
              </div>
              

            </div>
          </div>
        </div>
        <div class="right">
          <div class="title">能力分类</div>

          <div ref="pie-charts1" style="width: 100%;height: 100%" id="pie-charts1">

          </div>
        </div>
      </div>
      <div class="bottom-content">
        <div class="left">
          <div class="title">能力行业分析</div>

          <div ref="pie-charts2" style="width: 100%;height: 100%" id="pie-charts2"></div>

        </div>
        <div class="right">
          <div class="title">能力被调用趋势图</div>
          <div class="tool">
            <div @click="chaneActive" :class="[ active ? 'active' : '']" class="seven">最近7天</div>
            <div @click="chaneActive" :class="[ active ? '' : 'active']" class="thirty">最近30天</div>
          </div>
          <div ref="line-charts1" style="width: 100%;height: 90%;transform: translateY(20px);" id="line-charts1"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.home-container{
  height: 100%;
  padding: 10px 10px;
  position: relative;
  .home-content{
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top-content{
      width: 100%;
      height: 230px;
      display: flex;
      margin-bottom: 20px;
      justify-content: space-between;
      .left{
        width: 60%;
        height: 230px;
        background-color: #fff;
        border-radius: 5px;
        position: relative;
        .title{
          position: absolute;
          font-size: 14px;
          left: 30px;
          top: 30px;
        }
        .content{
          padding: 0 0;
          padding-top: 40px;
          height: 100%;
          width: 100%;
          display: flex;
          .inner-item{
            width: 33.3%;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            
            .digit{
              display: flex;
              align-items: baseline;
              .big-num{
                font-size: 24px;
                margin-right: 10px;
                position: relative;
                .type{
                  width: 100px;
                  position: absolute;
                  left: 0;
                  bottom: -20px;
                  font-size: 10px;
                }
              }
              .arrow{
                margin-left: 10px;
                height: 10px;
                border: 1px solid #8e8d8d;
                position: relative;
                .rotate{
                  position: absolute;
                  height: 5px;
                  top: -1px;
                  left: 1px;
                  transform: rotate(-45deg);
                  border: 1px solid #8e8d8d;
                }
              }
            }
          }
        }
      }
      .right{
        width: 39%;
        height: 230px;
   
        background-color: #fff;
        border-radius: 5px;
        position: relative;
        .title{
          position: absolute;
          font-size: 14px;
          left: 30px;
          top: 30px;
        }
      }

    }
    .bottom-content{
      flex: 1;
      width: 100%;
      display: flex;
      justify-content: space-between;
      .left{
        width: 42%;
        height: 100%;
    
        background-color: #fff;
        border-radius: 5px;
        position: relative;
        .title{
          position: absolute;
          font-size: 14px;
          left: 30px;
          top: 30px;
        }
        
      }
      .right{
        width: 57%;
        height: 100%;
        
        background-color: #fff;
        border-radius: 5px;
        position: relative;
        .title{
          position: absolute;
          font-size: 14px;
          left: 30px;
          top: 30px;
        }
        .tool{
          position: absolute;
          top: 10px;
          right: 20px;
          display: flex;
          z-index: 999;
          .seven{
            width: 98px;
            height: 43px;
            line-height: 43px;
            text-align: center;
            border: 1px solid #d7d7d7;
          }
          .thirty{
            width: 98px;
            height: 43px;
            line-height: 43px;
            text-align: center;
            border: 1px solid #d7d7d7;
          }
          .active{
            background-color: rgb(81,159,232);
            color: #fff;
          }
        }
      }

    }
  }
}

</style>

